#include "AppInstance.h"

CAppInstance * CAppInstance::s_AppInstance = nullptr;

CAppInstance * CAppInstance::GetInstance()
{
	if (CAppInstance::s_AppInstance != nullptr)
	{
		return CAppInstance::s_AppInstance;
	}

	CAppInstance::s_AppInstance = new CAppInstance();

	return CAppInstance::s_AppInstance;
}

CAppInstance::CAppInstance() :
	m_AppArgc(0),
	m_AppArgv(nullptr)
{
}

CAppInstance::~CAppInstance()
{
}

void CAppInstance::SetArgument(int argc, char * argv[])
{
	this->m_AppArgc = argc;
	this->m_AppArgv = argv;
}

int CAppInstance::GetArgumentCount()
{
	return this->m_AppArgc;
}

char ** CAppInstance::GetArgumentVector()
{
	return this->m_AppArgv;
}

void CAppInstance::SetThreadPrivateData(void * privateData)
{
	std::lock_guard<std::mutex> lockGuard(this->m_ThreadPrivateDataLock);

	this->m_ThreadPrivateDataTable[std::this_thread::get_id()] = privateData;
}

void * CAppInstance::GetThreadPrivateData()
{
	std::lock_guard<std::mutex> lockGuard(this->m_ThreadPrivateDataLock);

	if (this->m_ThreadPrivateDataTable.find(std::this_thread::get_id()) == 
		this->m_ThreadPrivateDataTable.end())
	{
		return nullptr;
	}

	return this->m_ThreadPrivateDataTable[std::this_thread::get_id()];
}